package com.clothing.interceptor;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.clothing.utils.AjaxMsg;

/**
 * @ClassName: BaseInterceptor
 * @Description: TODO(拦截器基类)
 * @author Administrator
 * @date 2017年1月11日 下午5:37:13
 * @version 1.0
 */
public class BaseInterceptor extends HandlerInterceptorAdapter
{
    protected boolean forbid(HttpServletResponse response, String msg)
            throws IOException
    {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, msg);
        return false;
    }

    protected boolean errorMsg(HttpServletResponse response, String msg)
            throws IOException
    {
        response.setCharacterEncoding("UTF-8");
        response.getWriter().println(AjaxMsg.failed(msg));
        response.getWriter().flush();
        return false;
    }
    
    protected boolean parameterErrorMsg(HttpServletResponse response)
            throws IOException
    {
        return errorMsg(response, "参数错误");
    }
    
    protected boolean permissionDeniedMsg(HttpServletResponse response)
            throws IOException
    {
        return errorMsg(response, "权限不足");
    }
}
